package com.example.myapplication.tutorial

import android.graphics.Color
import com.facebook.litho.Column
import com.facebook.litho.annotations.FromEvent
import com.facebook.litho.annotations.OnEvent
import com.facebook.litho.annotations.Prop
import com.facebook.litho.sections.Children
import com.facebook.litho.sections.SectionContext
import com.facebook.litho.sections.annotations.GroupSectionSpec
import com.facebook.litho.sections.annotations.OnCreateChildren
import com.facebook.litho.sections.common.DataDiffSection
import com.facebook.litho.sections.common.RenderEvent
import com.facebook.litho.sections.common.SingleComponentSection
import com.facebook.litho.sections.widget.RecyclerCollectionComponent
import com.facebook.litho.widget.ComponentRenderInfo
import com.facebook.litho.widget.RenderInfo
import com.facebook.yoga.YogaEdge
import com.fenbi.tutor.live.module.large.large.chat.lithoview.MsgInfo


/**
 * TODO 简要描述
 * @author wkm @ Zebra Inc.
 * @since 09-20-2020
 */
@GroupSectionSpec
object Root2Spec {
    private const val MAIN_SCREEN = "main_screen"

//    @OnCreateLayout
//    fun onCreateLayout(
//        c: ComponentContext?,
//        @Prop msgInfo: List<MsgInfo>?
//    ): Component {
//        return RecyclerCollectionComponent.create(c)
//            .disablePTR(true)
//            .section(
//                DataDiffSection.create<MsgInfo>(SectionContext(c))
//                    .data(msgInfo)
//                    .renderEventHandler(Root2.onRender(c))
//                    .build()
//            )
//            .paddingDip(YogaEdge.TOP, 8f)
//            .testKey(MAIN_SCREEN)
//            .build()
//    }

    @OnEvent(RenderEvent::class)
    fun onRender(c: SectionContext, @FromEvent model: MsgInfo): RenderInfo {
        return ComponentRenderInfo.create()
            .component(
                Column.create(c)
                    .heightDip(30F)
                    .backgroundColor(Color.RED)
                    .build()
            )
            .build()
    }

    @OnCreateChildren
    fun onCreateChildren(
        c: SectionContext, @Prop msgInfo: List<MsgInfo>?
    ): Children? {
        return Children.create()
            .child(
                SingleComponentSection.create(c)
                    .component(
                        RecyclerCollectionComponent.create(c)
                            .disablePTR(true)
                            .section(
                                DataDiffSection.create<MsgInfo>(SectionContext(c))
                                    .data(msgInfo)
                                    .renderEventHandler(Root2.onRender(c))
                                    .build()
                            )
                            .paddingDip(YogaEdge.TOP, 8f)
                            .testKey(MAIN_SCREEN)
                            .build()
                    )
                    .build()
            )
            .build()
    }
}
